package com.wilson.treeviewer.view;

import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;

import com.wilson.treeviewer.model.UserNode;
import com.wilson.treeviewer.model.UserTree;

public class UserTreeModel implements TreeModel {

    private final UserTree tree;

    public UserTreeModel(UserTree tree) {
        this.tree = tree;
    }

    @Override
    public Object getRoot() {
        return tree.getRoot();
    }

    @Override
    public Object getChild(Object parent, int index) {
        UserNode parentNode = (UserNode) parent;
        return parentNode.getChildren().get(index);
    }

    @Override
    public int getChildCount(Object parent) {
        UserNode parentNode = (UserNode) parent;
        return parentNode.getChildren().size();
    }

    @Override
    public boolean isLeaf(Object node) {
        return ((UserNode) node).getChildren().isEmpty();
    }

    @Override
    public int getIndexOfChild(Object parent, Object child) {
        UserNode parentNode = (UserNode) parent;
        return parentNode.getChildren().indexOf(child);
    }

    @Override
    public void valueForPathChanged(TreePath path, Object newValue) {
        // TODO Auto-generated method stub

    }

    @Override
    public void addTreeModelListener(TreeModelListener l) {
        // TODO Auto-generated method stub

    }

    @Override
    public void removeTreeModelListener(TreeModelListener l) {
        // TODO Auto-generated method stub

    }

}
